function addCompGrid(obj,parent,name)

% This file is part of CISNE.
%
%     CISNE is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     any later version.
%
%     CISNE is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
%
%     You should have received a copy of the GNU General Public License
%     along with CISNE.  If not, see <http://www.gnu.org/licenses/>.

% Copyright 2011. Jose Maria Garcia-Valdecasas Bernal

model=get(obj.m_tree,'model');
root=obj.m_tree.Root();
persistent gridCount;%unique number for grids.
if isempty(gridCount)
    gridCount=1;
end
for j=0:get(root,'ChildCount')-1
    child=root.getChildAt(j);
    kind=child.getValue();
    kind=char(kind(2));
    if (strcmp(kind,'COMPUTATIONAL'))
        %we add grids in COMPUTATIONAL GRIDS branch.
        if strcmp(parent,'NONE')
            grid=child;
            
            type=['cMain' num2str(gridCount)];
            gridCount=gridCount+1;
        else
            grid=obj.getNodeByName(child,parent);
            type=['cNest' num2str(gridCount)];
            gridCount=gridCount+1;
        end
        
        child=uitreenode('v0',{'unselected',type},name,[], false);
        model.insertNodeInto(child,grid,grid.getChildCount());
        %generate data for propertygrid
        obj.m_grids.(type)=...
            {'X0', 'Value of minimum X position', 'num',0;...
            'Y0', 'Value of minimum Y position', 'num',0;...
            'X Length', 'Length of grid in X axis', 'num',0;...
            'Y Length', 'Length of grid in Y axis', 'num',0;...
            'Dx', 'Discretization step in X axis', 'num',0;...
            'Dy', 'Discretization step in Y axis', 'num',0;...
            'Angle', 'Angle formed between East and X axis', 'num',0};
        obj.m_tree.setSelectedNode(child);
        handles=guidata(obj.m_figure);
        handles.DisplayWidget.setAction('new');
        handles.DisplayWidget.addCompGrid(type);
        set(handles.figure1,'Pointer','crosshair');
    end
end
end
        